package com.biaobiaoqi.scoreanalysis.administrator.action;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.biaobiaoqi.scoreanalysis.exception.DuplicateSchoolYearException;
import com.biaobiaoqi.scoreanalysis.service.ISchoolyearService;
import com.biaobiaoqi.scoreanalysis.util.Semester;
import com.opensymphony.xwork2.ActionSupport;

public class AddSchoolYear extends ActionSupport {
	private static final Log log = LogFactory.getLog(AddSchoolYear.class);
	private static final long serialVersionUID = -4372056658064562633L;
	private int beginYear;
	private int endYear;
	private Semester semester;

	@Resource
	private ISchoolyearService schoolyearService;

	public String execute() {
		log.debug("add school year");
		try {
			schoolyearService.addSchoolYear(beginYear, endYear, semester);
			return SUCCESS;
		} catch (DuplicateSchoolYearException e) {
			addActionError("学期已存在！");
			log.debug("学期已存在,开始年份："+beginYear+" 结束年份："+endYear+" semester："+semester,e);
			return INPUT;
		} catch (Exception e) {
			addActionError("服务器内部错误");
			log.error("服务器内部错误",e);
			return ERROR;
		}
	}

	public int getBeginYear() {
		return beginYear;
	}

	public void setBeginYear(int beginYear) {
		this.beginYear = beginYear;
	}

	public int getEndYear() {
		return endYear;
	}

	public void setEndYear(int endYear) {
		this.endYear = endYear;
	}

	public Semester getSemester() {
		return semester;
	}

	public void setSemester(Semester semester) {
		this.semester = semester;
	}

}
